import java.util.*;

class Student {

}

public class TestMapSet {

    public static void main(String[] args) {
        Set<String> set=new TreeSet<String>();
        set.add("abd");
        set.add("hello");
        set.add("abd");
//        System.out.println(set);
        Iterator<String> it=set.iterator();
        while(it.hasNext()) {
            System.out.println(it.next());
        }
    }

    public static void main2(String[] args) {
        Map<Student,String> map=new TreeMap<>();
        map.put(new Student(),"宋江");

    }


    public static void main1(String[] args) {
        Map<String,String> map=new TreeMap<>();//底层就是二叉搜索树
        map.put("及时雨","宋江");
        map.put("齐天大圣","孙悟空");
        String val=map.get("齐天大圣");
        System.out.println(val);

        String val2=map.get("齐天大圣2");//当输入的key,map中没有时,便会输出null
        System.out.println(val2);

        //可以给没有对应key的val,可以给一个默认值,使用getOrDefault方法
        String val3=map.getOrDefault("齐天大圣2","haha");
        System.out.println(val3);

        //remove
        String val4=map.remove("齐天大圣");
        System.out.println(val4);

        map.put("及时雨","宋江2");
        map.put("齐天大圣","孙悟空");
        Set<String> set=map.keySet();//将map中的key都拿出来,放入set中,重复值只放一次
        System.out.println(set);

        //同时返回key和map
        Set<Map.Entry<String,String>> entries=map.entrySet();
//        System.out.println(entries);

        for(Map.Entry<String,String> entry:entries) {
            System.out.println("key:"+entry.getKey()+",val:"+entry.getValue());
        }
    }
}
